package cn.itcast.service.impl;

import cn.itcast.dao.MemberDao;
import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.pojo.Member;
import cn.itcast.service.MemberService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.Page;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @Author: ZHT
 * @Dtae: 2021/11/15 16:25
 * @Version: 1.0
 */

@Service(version = "1.0.0")
@Slf4j
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao member;

    /**
     * 查询全部
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //开启分页查询
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        if(queryPageBean.getQueryString()==null){
            Page<Member> memberPage = member.findPage();
            PageResult pageResult = new PageResult(memberPage.getTotal(),memberPage.getResult());
            System.out.println(pageResult);
            return pageResult;
        }
        //调用dao
        Page<Member> memberPage = member.findTj(queryPageBean.getQueryString());

        PageResult pageResult = new PageResult(memberPage.getTotal(),memberPage.getResult());
        return pageResult;
    }

    /**
     * 根据id查询
     * @param userId
     * @return
     */
    @Override
    public Member tanChu(Integer userId) {
        return member.tanchu(userId);

    }

    @Override
    public Boolean update(Member membervo) {
        return member.update(membervo);

    }

    @Override
    public Boolean add(Member membervo) {
        long l = System.currentTimeMillis();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String d = sdf.format(l);// 时间戳转换成时间
        Date date = null;
        try {
             date = sdf.parse(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return member.add(membervo,date);

    }

    @Override
    public Boolean updateStatus(Integer userId, Integer status) {
        member.updateStatus(userId,status);

        return null;
    }

    /*
    * 修改数据
    * */

}
